package cn.bdqn.demo.seckill;

import cn.bdqn.demo.bean.Order;
import cn.bdqn.demo.ex.ServiceException;
import cn.bdqn.demo.service.OrderService;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class OrderJmsReceiverService {
    @Resource
    OrderService orderService;

    /**
     * 收到订单消息，保存订单到数据库
     * @param order
     */
    @JmsListener(destination = "ORDER_QUEUE")
    public void receive(Order order) {
        try {
            orderService.add(order);
        } catch (ServiceException e) {
            e.printStackTrace();
            //需要把失败的订单记录下来，手动导入到数据库
        }
        System.out.println(System.currentTimeMillis()+":保存订单成功");
    }
}
